import java.util.ArrayList;


public class RiceRecommend {
	public int Lunch;
	public int Dinner;
	public int[] ALunch=new int[5];
	public int[] LunchTime=new int[5];
	public int[] ADinner=new int[5];
	public int[] DinnerTime=new int[5];
	public double s = 0;         //SΪ�Ƽ�����
	public double coe1 = 0;      //coe1Ϊ���ϵ��1
	public double timeDiff = 0;  //timeDiffΪ�ò�ʱ���// int����a����Ϊ2  a[1]Ϊб�ʣ�a[0]Ϊ�ؾ�
	public RiceRecommend(){
	}
	public RiceRecommend(String Sno){
    	ArrayList<PeopleAction> action=new DatabaseOperate().actionquery("sNo","2011212095");
    	int m=0,n=0;
    	for(int i=action.size()-1;i>=0;i--){
    		if(action.get(i).getLunchAppetite()!=-1 && m<5){
    			ALunch[m]=action.get(i).getLunchAppetite();
    			LunchTime[m]=action.get(i).getMinute();
    			m++;
    		}
    		if(action.get(i).getDinnerAppetite()!=-1 && n<5){
    			ADinner[n]=action.get(i).getDinnerAppetite();
    			DinnerTime[n]=action.get(i).getMinute();
    			n++;
    		}
    	}
    	for(int i=0;i<m;i++)
    		Lunch+=ALunch[i];
    	for(int i=0;i<n;i++)
    		Dinner+=ADinner[i];
    	if(m!=0)
    		Lunch/=m;
    	else Lunch=-1;
    	if(n!=0)
    		Dinner/=n;
    	else Dinner=-1;
	}
	public double[] SPT(int[] x,int[] y ,int n){
		double[] a= new double[2];
		int i;
		int xx,yy,e,f,q;
		xx = yy = 0;
		
		for(i=0;i<n;i++){
			xx = xx + x[i]/n;
			yy = yy + y[i]/n;
		}
		
		e = f = 0;
		
		for(i=0;i<n;i++){
			q = x[i] - xx;
			e = e + q*q;
			f = f + q*(y[i]-yy);
		}
		
		a[1] = (double)f/(double)e;
		a[0] = yy - a[1]*xx;
		
		return a;
	}
    
	public int RecommandAppetite(int currentTime){
		double[] a= new double[2];
		if(currentTime>=660 && currentTime<=810){   //����ʱ��Ϊ�緹ʱ���
			a = SPT(ALunch,LunchTime,5);
			s = (currentTime - a[0])/a[1];
		}
		else if(currentTime>=990 && currentTime<=1140){  //����ʱ��Ϊ�?ʱ���
			a = SPT(ADinner,DinnerTime,5);
			s = (currentTime - a[0])/a[1];
		}
		else {
			if(currentTime<=990){
				s = Lunch;
			}
			else s = Dinner;
		}
		
		return (int)s;
	}
	public static void main(String[] args){
		System.out.println(new RiceRecommend("2011212095").RecommandAppetite(700));
		System.out.println(new RiceRecommend("2011212095").RecommandAppetite(1000));
	}
}